﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AspNetCs.Bll;
using System.Data;
using AspNetCs.Common;
using AspNetCs.Model;

public partial class Master_Admin_photoClass : Admin_BasePage
{
    protected UserPhoto UphotoBll = new UserPhoto();
    protected int Classid = 0;

    protected string NodelId = "1,2,3,4,5,6,7,8,9";//禁止删除的ID

    protected void Page_Load(object sender, EventArgs e)
    {
        IsExit();
        if (Request["Classid"] != null)
        {
            Classid = StringHelper.isNumber_int(Request["Classid"].ToString());
        }
        if (Classid < 0)
        {
            ShowMsgBack("参数传递错误!");
            Response.End();
        }
        if (!Page.IsPostBack)
        {
            bind();
        }



    }
    protected void bind()
    {
        this.GridView1.DataSource = UphotoBll.GetDataTable_Class("");
        this.GridView1.DataBind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        bind();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        UserPhoto_Class_Model md = new UserPhoto_Class_Model();
        int hid = StringHelper.isNumber_int(((HiddenField)GridView1.Rows[e.RowIndex].FindControl("Txt_hid")).Value);
        string newName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Txt_ClasName")).Text;
        string newReadme = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Txt_Readme")).Text;

        md.Id = hid;
        md.ClassName = newName;
        md.Readme = newReadme;
        UphotoBll.UpdateClass(md);
        GridView1.EditIndex = -1;
        bind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            // DataRowView drv = (DataRowView)e.Row.DataItem;
            // Response.Write(drv["id"].ToString());

            foreach (string str in StringHelper.SplitString(NodelId, ","))
            {
                if (str.Trim().ToLower() == GridView1.DataKeys[e.Row.RowIndex].Value.ToString().Trim().ToLower())
                {
                    (e.Row.FindControl("LinkButton1") as LinkButton).Enabled = false;
                    (e.Row.FindControl("LinkButton2") as LinkButton).Enabled = false;
                }
            }
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int id = StringHelper.isNumber_int(GridView1.DataKeys[e.RowIndex].Value.ToString());
        if (UphotoBll.delClass(id) > 0)
        {
            ResultStr("Admin_photoClass.aspx", "删除成功");
        }
        else
        {
            ShowMsgBack("删除失败!");
        }
        Response.End();
    }
}
